﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Meeting.Public;
using Newtonsoft.Json;

namespace Meeting.Web.Admin.Summary
{
    /// <summary>
    /// SummaryOperation 的摘要说明  会议纪要相关操作
    /// </summary>
    public class SummaryOperation : IHttpHandler
    {

        string methodName = "";
        int nPageIndex = 1;
        int nPageSize = 4;

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json;charset=utf-8";

            nPageIndex = CommonFunction.varToIntDef(context.Request.Params["page"], 1);
            nPageSize = CommonFunction.varToIntDef(context.Request.Params["rows"], 15);
            methodName = context.Request.Params["method"];
            switch (methodName)
            {
                case "GetAllSummary":
                      GetAllSummary(context);
                    break;
                case "DeleteSummary":
                    DeleteSummary(context);
                    break;
               
            }
        }

        //获取 
        private void GetAllSummary(HttpContext context)
        {
            string Name = CommonFunction.removeAttackOfSql(context.Request.Params["Name"]);

            string Begin = context.Request.Params["Begin"];
            string End = context.Request.Params["End"];

            string sF = " 1=1 ";
            if (!string.IsNullOrEmpty(Name)) sF += " And  Name Like '%" + Name + "%' ";

            if (!string.IsNullOrEmpty(Begin)) sF += " And UploadDate >= '" + Begin + "' ";
            if (!string.IsNullOrEmpty(End)) sF += " And  UploadDate <= '" + End + "' ";
            BLL.Summary bll = new BLL.Summary();
            context.Response.Write(bll.GetAllSummary(nPageIndex, nPageSize, sF));
        }
        //删除 
        private void DeleteSummary(HttpContext context)
        {
            string id = context.Request["Id"];
            BLL.Summary bll = new BLL.Summary();
            Model.JsonResponse rs = new Model.JsonResponse();
            rs.success = bll.DeleteTopic(id);
            rs.Message = bll.errorString;
            context.Response.Write(JsonConvert.SerializeObject(rs));

        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}